package com.itkjb.leisurely.resource.sys.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.itkjb.leisurely.core.base.BaseModelWithOperationFields;
import com.itkjb.leisurely.core.interfaces.TierInterface;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 字典分组
 * </p>
 *
 * @author itkjb.com
 * @since 2020-08-14
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("sys_dict_group")
@ApiModel(value = "SysDictGroupModel-模型", description = "字典分组")
public class SysDictGroupModel extends BaseModelWithOperationFields implements TierInterface {

    private static final long serialVersionUID = 1L;
    /**
     * id
     */
    @ApiModelProperty(value = "id")
    private String id;
    /**
     * 分组名称
     */
    @ApiModelProperty(value = "分组名称")
    @TableField("`name`")
    private String name;
    /**
     * 父级id
     */
    @ApiModelProperty(value = "父级id")
    @TableField("`parent_id`")
    private String parentId;
    /**
     * 父级名称
     */
    @ApiModelProperty(value = "父级名称")
    @TableField("`parent_name`")
    private String parentName;
    /**
     * 下级数量
     */
    @ApiModelProperty(value = "下级数量")
    @TableField("`sub_count`")
    private Integer subCount;

    @ApiModelProperty(value = "是否含有子节点")
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private  boolean hasChildren;

    public boolean isHasChildren(){
        return  (this.getSubCount() !=null && this.getSubCount()>0 )?true: false ;
    }

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序")
    @TableField("`paixu`")
    private Integer paixu;
    /**
     * 描述
     */
    @ApiModelProperty(value = "描述")
    @TableField("`description`")
    private String description;
    /**
     * 状态  0：禁用 ，1： 可用
     */
    @ApiModelProperty(value = "状态  0：禁用 ，1： 可用")
    @TableField("`status`")
    private Integer status;
    /**
     * 乐观锁版本号
     */
    @ApiModelProperty(value = "乐观锁版本号")
    @Version
    @NotNull(message = "缺少版本号参数")
    @TableField("`lock_version`")
    private Long lockVersion;

}
